package com.sangmo.fts.process.inventory.model;

import com.sangmo.boot.framework.data.entity.general.LongEntity2;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Goods;
import com.sangmo.fts.common.IConstants;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;

@Entity
@Table(name = "if_lading_bill_item")
@DataView
@ExtView
public class IfLadingBillItem extends LongEntity2 {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long billId;

    @One(value = "goods", target = Goods.class)
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long goodsId;

    @DataField(value = IConstants.DATA_TYPE.DECIMAL_POSITIVE_MONEY, required = true)
    private BigDecimal quantity;

    public Long getBillId() {
        return billId;
    }

    public void setBillId(Long billId) {
        this.billId = billId;
    }

    public Long getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Long goodsId) {
        this.goodsId = goodsId;
    }

    public BigDecimal getQuantity() {
        return quantity;
    }

    public void setQuantity(BigDecimal quantity) {
        this.quantity = quantity;
    }

    public static IfLadingBillItem fromStockItem(IfStockItem item) {
        if (null == item) {
            return null;
        } else {
            IfLadingBillItem ladingBillItem = new IfLadingBillItem();
            ladingBillItem.setGoodsId(item.getGoodsId());
            ladingBillItem.setQuantity(item.getQuantity());
            return ladingBillItem;
        }
    }
}

